package com.ruoyi.bzjgl.controller;

import com.ruoyi.bzjgl.domain.LegalCaseBasic;
import com.ruoyi.bzjgl.domain.TreeAjxz;
import com.ruoyi.bzjgl.service.ICaseNatureService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("案件性质管理")
@RestController
@RequestMapping("/system/caseNature")
public class CaseNatureController  extends BaseController {

    @Autowired
    private ICaseNatureService caseNatureService;

    //案件性质树形查询
    @ApiOperation("案件性质树形查询")
    @PostMapping("/treeList")
    public List<TreeAjxz> treeList()
    {
        List<TreeAjxz> treeList = caseNatureService.selectAjxz(null);
        return treeList;
    }


    //案件性质树形查询
    @ApiOperation("案件性质树形查询")
    @GetMapping("/getTreeList")
    public TableDataInfo getTreeList(String mc)
    {

        List<TreeAjxz> treeList = caseNatureService.selectAjxz(mc);
        return getDataTable(treeList);
    }

    //添加案件性质
    @ApiOperation("添加案件性质")
    @PostMapping("/insertCaseNature")
    public AjaxResult insertCaseNature(@RequestBody LegalCaseBasic legalCaseBasic)
    {
        return toAjax(caseNatureService.insertCaseNature(legalCaseBasic));
    }

    //删除案件性质
    @ApiOperation("删除案件性质")
    @GetMapping("/deleteCaseNature")
    public AjaxResult deleteCaseNature(String xh)
    {
        if("ROOT".equals(xh)){
            return AjaxResult.error("无法删除根节点");
        }
        List<LegalCaseBasic> list = caseNatureService.findChild(xh);
        if(list!=null){
            return AjaxResult.error("该节点有下级，请依次删除");
        }
        return toAjax(caseNatureService.deleteCaseNature(xh));
    }


    //修改案件性质
    @ApiOperation("修改案件性质")
    @PostMapping("/updateCaseNature")
    public AjaxResult updateCaseNature(@RequestBody LegalCaseBasic legalCaseBasic)
    {
        return toAjax(caseNatureService.updateCaseNature(legalCaseBasic));
    }
}
